package cn.clq.basic.service.impl;

import cn.clq.basic.mapper.BaseMapper;
import cn.clq.basic.query.BaseQuery;
import cn.clq.basic.service.IBaseService;
import cn.clq.basic.util.PageList;
import cn.clq.org.domain.Employee;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @author clqlongbao
 * @version 1.0
 * @description: TODO
 * @date 2022/6/8 15:24
 */
@Transactional(readOnly = true,propagation = Propagation.SUPPORTS)
public class BaseServiceImpl<T> implements IBaseService<T> {
    @Autowired
    private BaseMapper<T> baseMapper;

    @Override
    @Transactional
    public void save(T t) {
        baseMapper.save(t);
    }

    @Override
    @Transactional
    public void update(T t) {
        baseMapper.updateById(t);
    }

    @Override
    @Transactional
    public void removeById(Long id) {
        baseMapper.deleteById(id);
    }

    @Override
    @Transactional
    public void batchRemove(Long[] ids) {
        baseMapper.batchDelete(ids);
    }

    @Override
    public List<T> queryAll() {
        return baseMapper.loadAll();
    }

    @Override
    public T queryById(Long id) {
        return baseMapper.loadById(id);
    }

    @Override
    public PageList<T> queryPage(BaseQuery baseQuery) {
        //先查询总条数
        Long total = baseMapper.queryCount(baseQuery);
        //再查询总数据
        List<T> rows = baseMapper.queryData(baseQuery);
        return new PageList<T>(total,rows);
    }
}
